package com.example.its2021606134chh.TrafficViolationModule;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.its2021606134chh.R;

import java.util.List;

/**
 * @ClassName: TVSearchRVAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 10/8/2021$
 * @Version: 1.0
 */
public class TVSearchRVAdapter extends RecyclerView.Adapter<TVSearchRVAdapter.ViewHolder> {
    private Context context;
    private List<CarPeccancys> list;
    public TVSearchRVAdapter (List<CarPeccancys> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_tv_search_results, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CarPeccancys peccancys = list.get(position);
        holder.tvItemPaddr.setText(peccancys.getPaddr());
        holder.tvItemTime.setText(peccancys.getPdatetime());
        holder.tvItemCarNum.setText(peccancys.getCarnumber());
        holder.imgItemCar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.tvItemPaddr.setVisibility(View.GONE);
                holder.tvItemTime.setVisibility(View.GONE);
                holder.tvItemCarNum.setVisibility(View.GONE);
                holder.imgItemVideo.setVisibility(View.GONE);
                holder.imgItemCar.setVisibility(View.GONE);
                holder.myItemShow.setVisibility(View.VISIBLE);
                holder.btnItemTVBack.setVisibility(View.VISIBLE);
            }
        });
        holder.btnItemTVBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.myItemShow.setVisibility(View.GONE);
                holder.btnItemTVBack.setVisibility(View.GONE);
                holder.tvItemPaddr.setVisibility(View.VISIBLE);
                holder.tvItemTime.setVisibility(View.VISIBLE);
                holder.tvItemCarNum.setVisibility(View.VISIBLE);
                holder.imgItemVideo.setVisibility(View.VISIBLE);
                holder.imgItemCar.setVisibility(View.VISIBLE);
            }
        });
        holder.imgItemVideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, TVVideoActivity.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    //  添加数据
    public void addData(int position) {
        notifyItemChanged(position);
    }
    //  删除数据
    public void removeData(int position) {
        notifyItemChanged(position);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemPaddr, tvItemTime, tvItemCarNum;
        ImageView imgItemCar, imgItemVideo;
        Button btnItemTVBack;
        MyImgView myItemShow;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemPaddr = itemView.findViewById(R.id.tvItemPaddr);
            tvItemTime = itemView.findViewById(R.id.tvItemTime);
            tvItemCarNum = itemView.findViewById(R.id.tvItemCarNum);
            imgItemCar = itemView.findViewById(R.id.imgItemCar);
            imgItemVideo = itemView.findViewById(R.id.imgItemVideo);
            btnItemTVBack = itemView.findViewById(R.id.btnItemTVBack);
            myItemShow = itemView.findViewById(R.id.myItemShow);
        }
    }
}
